'use strict';

angular.module('metalabPartnerApp').directive('metaFormKeywords', function () {
    return {
        restrict: 'A',
        scope: {
            bindData: '=metaFormKeywords'
        },
        link: function (scope, elem) {
            elem.on('change', function () {
                var strs = elem.val().split(' ');
                var temp = [];
                strs.forEach(function (element) {
                    if (element) temp.push(element);
                });
                scope.bindData = temp;
                scope.$apply();
            });

            scope.$watch('bindData', function () {
                elem.val(scope.bindData.join(' '));
            }, true);
        }
    };
});
